#ifndef __API_PID_H
#define __API_PID_H

#include "stdint.h"
#include "FMS_Cavity_Base.h"

typedef struct
{
    u16 kp;
    u8 ki;
    u8 kd;
}pidPara_t;

typedef struct
{
    pidPara_t pid;
	
	u8 setMenu; 
	u8 setTemp;
	
    s16 integral;
	s16 lastDevi;
	u16 timeCount;
	u16 pwmOut;
	s8 keepWarmOffset;
	s8 stopHeatOffset;
	u8 stopTemp;
	u8 heatStep;
	u16 heatPipe;
	u16 pwmTime;
	u16 pwmTime_solw;
	
    s16 integral_A;
	s16 lastDevi_A;
	u16 timeCount_A;
    u16 pwmOut_A;
	s8 keepWarmOffset_A;
	s8 stopHeatOffset_A;
	u8 stopTemp_A;
    u8 heatStep_A;
	u16 heatPipe_A;
	u16 pwmTime_A;
	u16 pwmTime_solw_A;
}pidCB_t;
extern pidCB_t pidCB;

enum
{
	HEAT_STEP_FAST = 0,
	HEAT_STEP_SLOW,
	HEAT_STEP_KEEP_WARM,   
	HEAT_STEP_MAX,
};

enum
{
	HEAT_STEP_FAST_A = 0,
	HEAT_STEP_SLOW_A,
	HEAT_STEP_KEEP_WARM_A,    
	HEAT_STEP_MAX_A,
};

enum
{
	HEAT_ID_UP_OUT = 0,
	HEAT_ID_UP_IN,
	HEAT_ID_BOTTOM,
	HEAT_ID_SIDE_R,
	HEAT_ID_SIDE_L,
	HEAT_ID_LOOP_R,
	HEAT_ID_LOOP_L,
	HEAT_ID_BACK,
	
	HEAT_ID_STEAM_4,
	HEAT_ID_STEAM_3,
	HEAT_ID_STEAM_2,
	HEAT_ID_STEAM_1,
	HEAT_ID_STEAM_PTC,
	HEAT_ID_LAMP_Z,
	HEAT_ID_WATER_R,
	HEAT_ID_WATER_L,
	
	
	HEAT_ID_MAX,
};

extern const s8 stopHeatOffset1[MODE_MAX][21];

void Pid_Init(u8 menu,u8 setTemp);
static u16 Pid_Calculate(pidPara_t *pid,u8 realTemp,s8 offset);
u8 Pid_Process(u16 realTemp);
void Pid_HeatOnOff(u16 on,u16 off);
void Pid_HeatPipeCtrl(s8 heatId1,s8 heatId2);
u16 Pid_GetHeatPipeStatus(void);
void Pid_Init_A(u8 menu,u8 setTemp);
static u16 Pid_Calculate_A(pidPara_t *pid,u8 realTemp,s8 offset);
u8 Pid_Process_A(u16 realTemp);
void Pid_HeatPipeCtrl_A(s8 heatId1,s8 heatId2);

#endif
